<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>包租婆投诉</title>
<link rel="styleSheet" href="../../css/bootstrap.min.css"> 
<style type="text/css">
	#tableDiv{
		margin-left: 150px;
		margin-top: 80px;
		width: 600px;
	}
	
	#reasonDiv{
		margin-left: 150px;
		margin-top: 80px;
		width: 600px;
	}
	#complaintBt{
		float: right;
	}
		td{
		text-align: center;
	}
</style>
</head>
<body style="background-color: transparent;">
	<div id="tableDiv">
	<p><input type="hidden" id="ladyID" value="${sessionScope.myLandLady.ladyID }"></p>
	<p><input type="hidden" id="recordID"></p>
		<table id="ladyTable" class="table table-striped table table-bordered">
			<tr>
			<td>出租车位</td>
			<td>开始时间</td>
			<td>结束时间</td>
			<td>抢租客</td>
			</tr>
		</table>
	</div>

	<div id="reasonDiv">
	<p>投诉理由：</p>
	<p><textarea rows="5" cols="85" id="reasonArea" name="reasonArea" style="resize:none"></textarea></p>
	<label id="reasonMessage"></label>
	<p><button style="position:absolute;top:430px;left:700px;" class="btn btn-danger" id="complaintBt">投诉</button></p>
	</div>
</body>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	$(function(){
		init();
	})
	function init(){
		getRecordInfo();
	}
	function getRecordInfo(){
		var recordID = getParam("id");
		$("#recordID").val(recordID);
		var tr="";
		$.ajax({
			url:"getRecordInfo.do",
			type:"post",
			async:true,
			data:{"recordID":recordID},
			success:function(msg){
				var startTime = new Date(msg.purpose.rentInfo.startTime);
				var endTime = new Date(msg.purpose.rentInfo.endTime);
				tr+="<tr><td>"+msg.purpose.rentInfo.personalcarport.carportAddress+msg.purpose.rentInfo.personalcarport.carNO+"</td>"
					+"<td>"+startTime.getFullYear()+"年"+(startTime.getUTCMonth()+1)+"月"+(startTime.getUTCDate()+1)+"日"+startTime.getHours()+"时"+"</td>"
					+"<td>"+endTime.getFullYear()+"年"+(endTime.getUTCMonth()+1)+"月"+(endTime.getUTCDate()+1)+"日"+endTime.getHours()+"时"+"</td>"
					+"<td>"+msg.purpose.renter.renterName+"</td></tr>"
				$("#ladyTable").append(tr);
			}
		})
	}
	 function getParam(url){
		 var reg
		 = new RegExp("(^|&)"+
		 url +"=([^&]*)(&|$)");
		 var r
		 = window.location.search.substr(1).match(reg);
		if (r!=null) return unescape(r[2]); return null;
		
	 
	 }
	 $("#complaintBt").live("click",function(){
		 var recordID =$("#recordID").val();
		 var reason = $("#reasonArea").val();
		 if(checkLength()==true){
			 $.ajax({
				 url:"ladyComplaint.do",
				 type:"post",
				 async:true,
				 data:{"recordID":recordID,"reason":reason},
				 success:function(msg){
					 if(msg>0){
						 window.location.href="history.jsp";
					 }else{
						 alert("投诉失败！");
					 }
				 }
			 })
		 }
		
	 })
	 function checkLength(){
		 var reasonArea = $("#reasonArea").val();
		 if(reasonArea.length<5 || reasonArea.length >50){
			 $("#reasonMessage").html("投诉理由长度在5-50位之间");
			 return false;
		 }else{
			 return true;
		 }
		 
	 }
</script>
</html>